package com.yanqu.road.server.cmd.marriage.cross;

import com.yanqu.road.pb.marriage.MarriageProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.MarriageModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;


@Cmd(code = Protocol.S_CROSS_MARRIAGE_SET_CROSS_APPOINT, desc = "设置跨服指向联姻开关")
public class MarriageSetCrossAppointCmd extends AbstractCommand {

    private boolean isAcceptAppoint;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        MarriageProto.MarriageSetAppointReqMsg reqMsg = MarriageProto.MarriageSetAppointReqMsg.parseFrom(packet.getBytes());
        isAcceptAppoint = reqMsg.getIsAcceptAppoint();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(MarriageModule.class).setAcceptCrossAppoint(isAcceptAppoint);
    }

    @Override
    public void sendData(GamePlayer player) {
        MarriageProto.MarriageSetAppointRespMsg.Builder respMsg = MarriageProto.MarriageSetAppointRespMsg.newBuilder();
        respMsg.setRet(ret);
        player.sendPacket(Protocol.U_CROSS_MARRIAGE_SET_CROSS_APPOINT, respMsg);
    }
}
